package com.lebron.kotlin.ui.adapter

import android.support.v7.widget.AppCompatRatingBar
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lebron.kotlin.R
import com.lebron.kotlin.bean.movie.Subject

/**
 * @Author lebron
 * @Date 18-7-31-下午2:40
 * 电影列表页适配器
 */
class MovieListAdapter(data: MutableList<Subject>?) : BaseQuickAdapter<Subject, BaseViewHolder>(R.layout.item_fragment_list, data) {

    override fun convert(helper: BaseViewHolder?, item: Subject?) {
        helper?.setText(R.id.tv_movie_title, item?.title)
        Glide.with(mContext).load(item?.images?.large).into(helper?.getView(R.id.iv_movie_img) as ImageView)

        val ratingBar: AppCompatRatingBar = helper.getView(R.id.ratingBar_hots)
        if (item?.rating != null) {
            ratingBar.rating = item.rating.average.div(2).toFloat()
        }

        helper.setText(R.id.tv_movie_rating, item?.rating?.average.toString())
        var textActor: String = mContext.getString(R.string.string_actor)
        item?.casts?.forEach { cast ->
            textActor += "  " + cast.name
        }
        helper.setText(R.id.tv_movie_actor, textActor)

        var textDirector: String = mContext.getString(R.string.string_director)
        item?.directors?.forEach { director ->
            textDirector += "  " + director.name
        }
        helper.setText(R.id.tv_movie_director, textDirector)

        var textType: String = mContext.getString(R.string.string_type)
        item?.genres?.forEach { type ->
            textType += "  $type"
        }
        helper.setText(R.id.tv_movie_type, textType)
    }


}